package cn.ld.module.ai.dal.mapper.image;

import cn.ld.framework.common.pojo.PageResult;
import cn.ld.framework.mybatis.core.mapper.BaseMapperX;
import cn.ld.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.ld.module.ai.controller.admin.image.vo.AiImagePageInVO;
import cn.ld.module.ai.controller.admin.image.vo.AiImagePublicPageInVO;
import cn.ld.module.ai.dal.entity.image.AiImageEntity;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * AI 绘图 Mapper
 *
 * @author fansili
 */
@Mapper
public interface AiImageMapper extends BaseMapperX<AiImageEntity> {

    default AiImageEntity selectByTaskId(String taskId) {
        return selectOne(AiImageEntity::getTaskId, taskId);
    }

    default PageResult<AiImageEntity> selectPage(AiImagePageInVO inVO) {
        return selectPage(inVO, new LambdaQueryWrapperX<AiImageEntity>()
                .eqIfPresent(AiImageEntity::getUserId, inVO.getUserId())
                .eqIfPresent(AiImageEntity::getPlatform, inVO.getPlatform())
                .eqIfPresent(AiImageEntity::getStatus, inVO.getStatus())
                .eqIfPresent(AiImageEntity::getPublicStatus, inVO.getPublicStatus())
                .betweenIfPresent(AiImageEntity::getCreateTime, inVO.getCreateTime())
                .orderByDesc(AiImageEntity::getId));
    }

    default PageResult<AiImageEntity> selectPageMy(Long userId, AiImagePageInVO inVO) {
        return selectPage(inVO, new LambdaQueryWrapperX<AiImageEntity>()
                .likeIfPresent(AiImageEntity::getPrompt, inVO.getPrompt())
                // 情况一：公开
                .eq(Boolean.TRUE.equals(inVO.getPublicStatus()), AiImageEntity::getPublicStatus, inVO.getPublicStatus())
                // 情况二：私有
                .eq(Boolean.FALSE.equals(inVO.getPublicStatus()), AiImageEntity::getUserId, userId)
                .orderByDesc(AiImageEntity::getId));
    }

    default PageResult<AiImageEntity> selectPage(AiImagePublicPageInVO pageInVO) {
        return selectPage(pageInVO, new LambdaQueryWrapperX<AiImageEntity>()
                .eqIfPresent(AiImageEntity::getPublicStatus, Boolean.TRUE)
                .likeIfPresent(AiImageEntity::getPrompt, pageInVO.getPrompt())
                .orderByDesc(AiImageEntity::getId));
    }

    default List<AiImageEntity> selectListByStatusAndPlatform(Integer status, String platform) {
        return selectList(AiImageEntity::getStatus, status,
                AiImageEntity::getPlatform, platform);
    }

}
